<template>
    <div id="CompanyFairDialog">
        <el-dialog title="添加招聘会" width="900px" :visible.sync="show">
            <vj-form @submit="onSubmit" @close="show=false" hide-reset :style-config="{labelWidth:'160px'}"
                     :slot-idx="cfgList.length"
                     :loading="loading" class="vj-form" :cfg-list="cfgList"
                     :form-data.sync="formData">
                <template slot="form-item">
                    <el-form-item required label="参与企业">
                        <el-button @click="companyDialog.open()">选择企业</el-button>
                        <el-button @click="fairDialog.open()">选择招聘会</el-button>
                    </el-form-item>
                    <vj-table style="margin-bottom: 20px" :pagination="false"
                              :page-obj="pageObj" :loading="loading" :cfg-list="tbCfgList"
                              :table-data="tableData">
                        <template #action="{id,idx}">
                            <text-button text="删除" @click="tableData.splice(idx,1)"/>
                        </template>
                    </vj-table>
                </template>
            </vj-form>
        </el-dialog>
        <company-list-dialog :list.sync="tableData" ref="companyDialog"/>
        <fair-list-dialog ref="fairDialog" @submit="companySubmit"/>
    </div>
</template>
<script lang="ts">
    import Vue, {ComponentOptions, VueConstructor} from "vue"
    import Component from 'vue-class-component'
    import {Mixins, PropSync, Ref} from "vue-property-decorator";
    import {FormMixin} from "@/plugins/mixins/form";
    import {ActivityFormTB, CompanyTB} from "@/config/table";
    import {ACTIVITY_FM, ACTIVITY_LINK_FM, CAPITAL_FM, COMPANY_FAIR_FM, JOB_FM, PIC_FM, TALENT_FM} from "@/config/form";
    import {cloneDeep, formatOptions, hookLoading, hookSubmit, updateCfgOption} from "vijay-util";
    import {requestByGet, requestByPost, requestByPut} from "@/utils/request";
    import CompanyTableDialog from "@/components/dialog/company/company-table-dialog.vue";
    import CompanyListDialog from "@/components/dialog/company/company-list-dialog.vue";
    import {TableMixin} from "@/plugins/mixins/table";
    import TextButton from "@/components/basic/text-button.vue";
    import FairListDialog from "@/components/dialog/company/fair-list-dialog.vue";

    @Component({
        components: {FairListDialog, TextButton, CompanyListDialog, CompanyTableDialog}
    })
    export default class CompanyFairDialog extends Mixins(FormMixin, TableMixin) implements ComponentOptions<Vue> {
        name = "CompanyFairDialog"
        show = false;
        editId = null;
        formData = {};
        cfgList = COMPANY_FAIR_FM
        @Ref() companyDialog!: any;
        @Ref() fairDialog!: any;
        tableData = [];
        tbCfgList = CompanyTB;
        @hookSubmit()
        async onSubmit() {
            const requestFn = this.editId ? requestByPut : requestByPost;
            await requestFn(`qqc/qqcRecjob/${this.editId ? 'edit' : 'add'}`, {
                ...this.formData,
                id: this.editId,
                qqcJobtitleList: this.tableData
            });
            this.$message.success("操作成功！");
            this.show = false;
            this.$emit('refresh')
        }
        companySubmit(companies) {
            console.log(companies)
        }
        open(data = {} as any) {
            this.show = true;
            this.formData = cloneDeep(data);
            this.editId = data.id;
        }
    }
</script>

<style scoped lang="scss">
    @import "~assets/common.scss";
    #CompanyFairDialog {
    }
</style>
